package top.huxy.boot.controller.admin;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.huxy.boot.annotation.Master;
import top.huxy.boot.annotation.RequestRemake;
import top.huxy.boot.model.entity.BackgroundImage;
import top.huxy.boot.service.BackgroundImageService;
import top.huxy.boot.util.obj.Result;

import java.util.List;


/**
 * @author HuXY
 * @since 2022-01-06 10:01:13
 */
@RestController
@RequestMapping("/admin/backgroundImage")
public class AdminBackgroundImageController {
    @Autowired
    private BackgroundImageService backgroundImageService;

    @GetMapping("/getBgList")
    @RequestRemake("获取天气图片列表")
    @Master
    public Result getBgList() {
        List<BackgroundImage> list = backgroundImageService.getBgList();
        return Result.success(list);
    }


    @PostMapping("/addBg")
    @RequestRemake("添加天气图片")
    @Master
    public Result addBg(Bg bg) {
        backgroundImageService.addBg(bg);
        return Result.success("添加成功");
    }

    @PostMapping("/delBg")
    @RequestRemake("删除天气图片")
    @Master
    public Result delBg(@RequestParam("id") String id) {
        backgroundImageService.delBg(id);
        return Result.success("删除成功");
    }

    @PostMapping("/updateBg")
    @RequestRemake("修改天气图片")
    @Master
    public Result updateBg(Bg bg) {
        backgroundImageService.updateBg(bg);
        return Result.success("修改成功");
    }
    @PostMapping("/setCurrent")
    @RequestRemake("修改天气图片")
    @Master
    public Result setCurrent(@RequestParam("id") String id) {
        backgroundImageService.setCurrent(id);
        return Result.success("设置成功");
    }


    @Data
    public static class Bg {
        private String id;
        private String src;
    }
}
